package com.tywj.lib.core.common.util

import android.app.Activity
import android.graphics.Color
import android.os.Build
import android.view.View
import android.view.Window
import android.view.WindowManager
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import com.blankj.utilcode.util.BarUtils

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/7
 *     desc   : 栏工具类
 *     version: 1.0.0
 * </pre>
 */
object BarUtil {

    /**
     * 设置浸入状态栏
     */
    fun invasionStatusBar(activity: Activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            val option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            activity.window.decorView.systemUiVisibility = option
            activity.window.statusBarColor = Color.TRANSPARENT
        }
    }

    fun setStatusBarColor(activity: Activity, @ColorInt color: Int) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            activity.window.statusBarColor = color
        }
    }

    fun setStatusBarColorRes(activity: Activity, @ColorRes idRes: Int) {
        setStatusBarColor(
            activity,
            ResourcesUtil.getColor(idRes)
        )
    }

    fun hideStatusBar(activity: Activity) {
        activity.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN)
    }

    fun setStatusBarLightMode(window: Window, isLightMode: Boolean) {
        BarUtils.setStatusBarLightMode(window, isLightMode)
    }

    fun getStatusBarHeight(): Int {
        val resources = AppUtil.context.resources
        val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
        return resources.getDimensionPixelSize(resourceId)
    }

    fun getNavigationBarHeight(): Int {
        val resources = AppUtil.context.resources
        val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
        return resources.getDimensionPixelSize(resourceId)
    }
}